package com.ruoyi.point.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.point.pojo.HistoryPanel;
import com.ruoyi.point.service.IHistoryPanelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 历史记录管理Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/system/panel")
public class HistoryPanelController extends BaseController
{
    @Autowired
    private IHistoryPanelService historyPanelService;

    /**
     * 查询历史记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:panel:list')")
    @GetMapping("/list")
    public TableDataInfo list(HistoryPanel historyPanel)
    {
        startPage();
        List<HistoryPanel> list = historyPanelService.selectHistoryPanelList(historyPanel);
        return getDataTable(list);
    }

    /**
     * 导出历史记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:panel:export')")
    @Log(title = "历史记录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HistoryPanel historyPanel)
    {
        List<HistoryPanel> list = historyPanelService.selectHistoryPanelList(historyPanel);
        ExcelUtil<HistoryPanel> util = new ExcelUtil<HistoryPanel>(HistoryPanel.class);
        util.exportExcel(response, list, "历史记录管理数据");
    }

    /**
     * 获取历史记录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:panel:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId)
    {
        return success(historyPanelService.selectHistoryPanelByEquipmentId(equipmentId));
    }

    /**
     * 新增历史记录管理
     */
    @PreAuthorize("@ss.hasPermi('system:panel:add')")
    @Log(title = "历史记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HistoryPanel historyPanel)
    {
        return toAjax(historyPanelService.insertHistoryPanel(historyPanel));
    }

    /**
     * 修改历史记录管理
     */
    @PreAuthorize("@ss.hasPermi('system:panel:edit')")
    @Log(title = "历史记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HistoryPanel historyPanel)
    {
        return toAjax(historyPanelService.updateHistoryPanel(historyPanel));
    }

    /**
     * 删除历史记录管理
     */
    @PreAuthorize("@ss.hasPermi('system:panel:remove')")
    @Log(title = "历史记录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable Long[] equipmentIds)
    {
        return toAjax(historyPanelService.deleteHistoryPanelByEquipmentIds(equipmentIds));
    }
}
